home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
lisp
/
eulisp
/
mpfeel.lha
/
MPFeel
/
Plurals
/
mp_object.h
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-15
|
4KB
|
154 lines
/*
* Objects
*
* Author: S.C.Merrall
*
* File: mp_object.h
*
* Contents:
*
* Description: I am attempting to write this code is an object
* orientated fashion. Objects in the system are
* always of the form make_OBJECT and these objects
* are accessed via functions from this file. They
* are all macros but this should give a nice
* generic feel to it.
*
* Change History:
*
* Date Name Comment
* -------- ---- -------
* 29:01:91 SCM Created
* 18:02:91 SCM Proper Naming convention plus generic accessors
* 19:04:91 SCM Added Dynamic creation of objects
* 19:04:91 SCM Added new class MP_PluralHeap
* 19:04:91 SCM Class MP_Type removed
* 27:05:91 SCM Class MP_PluralHeap no longer an object
* 28:06:91 SCM Combined free and type into 32 bit info field
*
*/
/* Object Verification On/Off Flag */
/* ====== ============ ====== ==== */
#define OD_OBJECT_CHECK on
/* Bit masks for info field */
/* === ===== === ==== ===== */
#define OD_FREE_FLAG_MASK 0x00000001
#define OD_TYPE_MASK (~0x00000001)
#define OM_type(OBJECT) ((OBJECT->Generic.info) & OD_TYPE_MASK)
#define OM_freep(OBJECT) (((OBJECT->Generic.info)&OD_FREE_FLAG_MASK)==OD_FREE_FLAG_MASK)
/* Static/Dynamic Flag Identifiers */
/* ============== ==== =========== =*/
#define OD_STATIC 0x00000000
#define OD_DYNAMIC 0x70000000
/* NOTE: these values are `ORed' with the Type Identifier => 31 types only */
/* Unique Identifiers */
/* ====== =========== */
#define OI_make 0x00000000
#define OI_MP_Context 0x00000002
#define OI_Generic 0xFFFFFFFF
/* Structure Common To All Objects And Definition Of Object */
/* ========= ====== == === ======= === ========== == ====== */
#define OD_COMMON_STRUCTURE int info; int (*destructor)(); object (*constructor)()
typedef union OU_object *object;
/* Headers Of Objects */
/* ======= == ======= */
#include "MP_Context.h"
#include "MP_PluralHeap.h" /* WARNING: these are not objects at all */
/* Definition Of Object Structure */
/* ========== == ====== ========= */
/*struct Generic_ {
int info;
int (*destructor)();
Object (*constructor)();
};
*/
struct Generic {OD_COMMON_STRUCTURE;};
union OU_object {
struct Generic Generic;
struct MP_Context MP_Context;
/* struct MP_PluralHeap MP_PluralHeap; */
};
/* Generic object functions */
/* ======= ====== ========= */
#ifdef OD_OBJECT_CHECK
#define OF_destroy(OBJECT) (error(OBJECT,"OF_destroy",OI_Generic)->Generic.destructor)(OBJECT)
#define OF_make(thing) (object)memcpy((char *)error((object *)malloc(sizeof(thing)),"OF_make",OI_make),(char *)&thing, sizeof(thing))
#define OF_create(OBJECT) (OBJECT.constructor)
#define OF_free(OBJECT) ((error(OBJECT,"OF_free",OI_Generic)->Generic.info)=(OBJECT->Generic.info)|OD_FREE_FLAG_MASK)
#else
#define OF_destroy(OBJECT) (OBJECT->Generic.destructor)(OBJECT)
#define OF_make(thing) (object)memcpy((char *)malloc(sizeof(thing)),(char *)&thing, sizeof(thing))
#define OF_create(OBJECT) (OBJECT.constructor)
#define OF_free(OBJECT) ((OBJECT->Generic.info)=(OBJECT->Generic.info)&OD_FREE_FLAG_MASK)
#endif
#define OF_stack(CLASS,NAME) struct CLASS NAME/**/_; object NAME = (object) memcpy((char *)& NAME/**/_, (char *)& DOC_/**/CLASS , sizeof(DOC_/**/CLASS))
/* Generic Object Accessor */
/* ======= ====== ======== */
#ifdef OD_OBJECT_CHECK
#else
#endif
/* Declaration of obejct checking function */
/* =========== == ====== ======== ======== */
#ifdef __STDC__
extern object error( object, char *,int );
extern object no_constructor( void );
#else
extern object error();
extern object no_constructor();
#endif
#define null(X) ((X == NULL) ? exit(fprintf(dbg,"ERROR: NULL pointer in %s called from %s\n",dbg_fname,old_dbg_fname)) : X)
/* Partial Generic object functions */
/* ======= ======= ====== ========= */